﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using DBUtility;

namespace ATSDAL
{
    public class DebReport : IDebReport
    {
        private const string PARM_TESTITEM_TYPE = "@ProductTypeID";
        private const string PARM_TESTITEM_SN = "@ProductSN";
        private const string PARM_TESTITEM_MO = "@MOID";
        private const string PARM_TESTITEM_STRATDATE = "@starttime";
        private const string PARM_TESTITEM_ENDDATE = "@stoptime";

        public DataSet GetDataByProType(string ProType)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_TYPE);
            testItemParms[0].Value = ProType;

            return ExcuteDataset("DebInfo_select_ProType", testItemParms);
        }
        
        public DataSet GetDataByProSN(string ProSN)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_SN);
            testItemParms[0].Value = ProSN;

            return ExcuteDataset("DebInfo_select_ProSN", testItemParms);
        }

        public DataSet GetDataByMO(string MOID)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO);
            testItemParms[0].Value = MOID;

            return ExcuteDataset("DebInfo_select_MO", testItemParms);
        }

        public DataSet GetDataByDate(DateTime StartDate, DateTime EndDate)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_STRATDATE, PARM_TESTITEM_ENDDATE);
            testItemParms[0].Value = StartDate;
            testItemParms[1].Value = EndDate;

            return ExcuteDataset("DebInfo_select_DT", testItemParms);
        }

        public DataSet ExcuteDataset(string spname, params SqlParameter[] parm)
        {
            DataSet set = new DataSet();
            set = sqlHelper.GetDataSet(spname, "De_Data", sqlHelper.ConnectionStringLocalTransaction, parm);

            return set;
        }


        #region 参数部分
        private static SqlParameter[] GetSNTParameters(string Par)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par, SqlDbType.Text),           
                };
            return parms;
        }

        private static SqlParameter[] GetSNTParameters(string Par1, string Par2)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par1, SqlDbType.DateTime, 8),
                    new SqlParameter(Par2, SqlDbType.DateTime, 8)
                };
            return parms;
        }
        #endregion
    }
}
